//
//  SWLoadConfig.m
//  SerialPort
//
//  Created by MT-SW-003 on 2021/4/9.
//  Copyright © 2021 MT-SW-003. All rights reserved.
//

#import "SWLoadConfig.h"

@implementation SWLoadConfig


/*
* load  json file from file path
*
* @param filePath File path.
*
*/
+ (id)loadJsonFile:(NSString *)filePath {
    id jsonData = nil;
    NSError *error;
    NSString *path = [[NSBundle mainBundle] pathForResource:filePath ofType:nil];
    if ([NSFileManager.defaultManager fileExistsAtPath:path]) {
        jsonData = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:0 error:&error];
        if (error) {
            NSLog(@"%@", error.localizedDescription);
        }
    }
    return jsonData;
    
}


/*
* load  plist file from file path.
*
* @param filePath File path.
*
*/
+ (id)loadPlistFile:(NSString *)filePath
{
    id plistData = nil;
    NSString *path = [[NSBundle mainBundle] pathForResource:filePath ofType:nil];
    if ([path class] == nil) {
        NSLog(@"open config.plist failed");
    }
    plistData = [NSDictionary dictionaryWithContentsOfFile:path];
    return plistData;
}

@end
